<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>项目列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <script src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
</head>

<body>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">

                    <div class="layui-card-header">

                        <button class="layui-btn" onclick="xadmin.open('添加用户','./order-add.html',800,600)">
                            <i class="layui-icon"></i>添加</button></div>
                    <div class="layui-card-body ">
                        <table class="layui-table layui-form">
                            <thead>
                                <tr>
                                    <th>
                                        <input type="checkbox" name="" lay-skin="primary">
                                    </th>
                                    <th>标题</th>
                                    <th>日化利率</th>
                                    <th>投资期限</th>
                                    <th>起投金额</th>
                                    <th>项目规模</th>
                                    <th>描述</th>
                                    <th>图片</th>
                                    <th>操作</th>
                            </thead>
                            <tbody>
                                {% for dc in devicecheck %}
                                <tr>
                                    <td>
                                        <input type="checkbox" name="" lay-skin="primary"></td>
                                    <td>{{dc.title}}</td>
                                    <td>{{dc.rihuali}}</td>
                                    <td>{{dc.touziqixian}}</td>
                                    <td>{{dc.qitoujine}}</td>
                                    <td>{{dc.xiangmuguimo}}</td>
                                    <td>{{dc.desc}}</td>
                                    <td><img class="layui-upload-img" id="demo1" src="/{{dc.img}}" onerror="/images/yf_default.png"></td>
                                    <td class="td-manage">
                                        <div class="layui-upload">
                                            <button type="button" class="layui-btn" id="test1"
                                                lay-data="{url: '/upload/{{dc.id}}', accept: 'images'}" }>上传图片</button>
                                            <div class="layui-upload-list">
                                                <img class="layui-upload-img" id="demo1">
                                                <p id="demoText"></p>
                                            </div>
                                        </div>
                                        <button onclick="member_del(this,{{dc.id}})" class="layui-btn">删除项目</button>
                                    </td>
                                </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>
                    <div class="layui-card-body ">
                        <div class="page">
                            <div id="demo0"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
<script>layui.use(['laydate', 'form', 'upload', 'laypage'],
        function () {
            var laydate = layui.laydate;
            var laypage = layui.laypage;
            var upload = layui.upload;

            laypage.render({
                elem: 'demo0'
                , count: {{ orderCount }} //数据总数
            });
    //执行一个laydate实例
    laydate.render({
        elem: '#start' //指定元素
    });

    //执行一个laydate实例
    laydate.render({
        elem: '#end' //指定元素
    });

    var uploadInst = upload.render({
        elem: '#test1'
        , before: function (obj) {
            //预读本地文件示例，不支持ie8
            obj.preview(function (index, file, result) {
                $('#demo1').attr('src', result); //图片链接（base64）
            });
        }
        , done: function (res) {
            console.log(res);
            //如果上传失败
            if (res.code > 0) {
                return layer.msg('上传失败');
            }
            //上传成功
        }
        , error: function () {
            //演示失败状态，并实现重传
            var demoText = $('#demoText');
            demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
            demoText.find('.demo-reload').on('click', function () {
                uploadInst.upload();
            });
        }
    });
        });

    /*用户-停用*/
    function member_stop(obj, id) {
        layer.confirm('确认要停用吗？',
            function (index) {

                if ($(obj).attr('title') == '启用') {

                    //发异步把用户状态进行更改
                    $(obj).attr('title', '停用');
                    $(obj).find('i').html('&#xe62f;');

                    $(obj).parents("tr").find(".td-status").find('span').addClass('layui-btn-disabled').html('已停用');
                    layer.msg('已停用!', {
                        icon: 5,
                        time: 1000
                    });

                } else {
                    $(obj).attr('title', '启用');
                    $(obj).find('i').html('&#xe601;');

                    $(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-disabled').html('已启用');
                    layer.msg('已启用!', {
                        icon: 5,
                        time: 1000
                    });
                }

            });
    }

    /*用户-删除*/
    function member_del(obj, id) {
        layer.confirm('确认要删除吗？',
            function (index) {
                $.ajax({
                    cache: false,
                    type: "POST",
                    url: "./delete/" + id,
                    contentType: "application/x-www-form-urlencoded; charset=utf-8",
                    async: false,
                    error: function (request) {
                        console.log("Connection error");
                        layer.open({
                            title: '删除失败'
                            , content: '未知错误，请稍后重试'
                        });
                    },
                    success: function (data) {
                        console.log(data);
                        //发异步删除数据
                        $(obj).parents("tr").remove();
                        layer.msg('已删除!', {
                            icon: 1,
                            time: 1000
                        });
                    }
                });

            });
    }

    function delAll(argument) {

        var data = tableCheck.getData();

        layer.confirm('确认要删除吗？' + data,
            function (index) {
                //捉到所有被选中的，发异步进行删除
                layer.msg('删除成功', {
                    icon: 1
                });
                $(".layui-form-checked").not('.header').parents('tr').remove();
            });
    }

</script>

</html>